package acidcart.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DecoratedPopupPanel;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class PopupFactory {
	
	public static void StandardAlert(String s)
	{
        Window.alert(s);
	}
	
	public static DialogBox StandardDialog(Widget w, String title)
	{
	    final DialogBox dialogBox = new DialogBox();
		dialogBox.setAnimationEnabled(true);
	    dialogBox.setGlassEnabled(true);
	    dialogBox.setText(title);
	    
	    VerticalPanel dialogContentPanel = new VerticalPanel();
	    dialogContentPanel.setWidth("100%");
	    dialogContentPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
	    
	    // Add widget to dialog box.
	    dialogContentPanel.add(w);
	    
	    // Add a close button at the bottom of the dialog
	    Button closeButton = new Button("Close");
	    closeButton.addClickHandler(new ClickHandler() {
          public void onClick(ClickEvent event) {dialogBox.hide();}
        });
		
	    dialogContentPanel.add(closeButton);
	    dialogBox.setWidget(dialogContentPanel);
	    
	    // Return the dialog box
	    return dialogBox;		
	}
	
	public static DecoratedPopupPanel StandardPopupBox(Widget w)
	{
	    final DecoratedPopupPanel decoPopup = new DecoratedPopupPanel(true);
	    decoPopup.setAnimationEnabled(true);
	    decoPopup.setWidget(w);
	    return decoPopup;
	}
	
	public static PopupPanel StandardImagePanel(Image img)
	{
	    final PopupPanel imagePopup = new PopupPanel(true);
	    imagePopup.setAnimationEnabled(true);
	    imagePopup.setWidget(img);
	    img.addClickHandler(new ClickHandler() {
	      public void onClick(ClickEvent event) {
	        imagePopup.hide();
	      }
	    });
		return imagePopup;
	}

}
